package ModelLayer;
import java.util.ArrayList;

/**
 * The DVD is both a container for the Class Copy, it has an ArrayList and also the class for individual DVDs
 * which is why it has a public constructor for creating different DVD's
 * 
 * @author Gruppe A 
 * @version 1.0
 */
public class Loan
{
    // instance variables - replace the example below with your own
    private int deliveryDateMonth;
    private int deliveryDateDay;
    private Person loanperson;
    private boolean home;
    private long id;
    private ArrayList<DVD> showdvds;
    private ArrayList<Copy> loandvds;

    /**
     * Constructor for objects of class Loan
     * @param String delvieryDate
     * @param Person loanperson
     * @param long id
     */
    public Loan(int deliveryDateMonth, int deliveryDateDay, Person loanperson, long id)
    
    {
        
        
        home = false;
        this.deliveryDateMonth = deliveryDateMonth;
        this.deliveryDateDay = deliveryDateDay;
       
        this.loanperson = loanperson;
        this.id = id;
        loandvds = new ArrayList<Copy>();
        showdvds = new ArrayList<DVD>();
    }
    

    /**
     * A method for adding a copy to the loan
     * @param Copy loandvd
     */
    public void dvdLoan(Copy loandvd)
    {
        loandvds.add(loandvd);
    }
    
    /**
     * A mutator method for setting a new loan id
     * @param long id
     */
    public void setId(long id)
    {
        this.id = id;
    }
    
    /**
     * A method for setting a new deliveryDateMonth, 
     * @param int deliveryDateMonth
     */
    public void setDeliveryDateMonth(int deliveryDateMonth)
   
    {
       
        this.deliveryDateMonth = deliveryDateMonth;
    }
    
    /**
     * An accessor method for showing the id of a loan
     * @return long id
     */
    public long getId()
    {
        return id;
    }
    
    /**
     * A method that adds the parent of a specific copy to the loan
     * @param DVD showdvd
     */
    public void dvdParent(DVD showdvd)
    {
        showdvds.add(showdvd);
    }

    /**
     * An accessor method showing the deliveryDate of a loan
     * @return int deliveryDateMonth
     */
    public int getDeliveryDateMonth()
    {
        return deliveryDateMonth;
    }
    
    /**
     * A method for changing the value of home to false, showing that the
     * current loan has not been returned.
     */
    public void loanedOut()
    {
        home = false;
    }
    
    
    /**
     * A method for changing the value of home to true, showing that the
     * current loan has been returned.
     */
    public void received()
    {
        home = true;
    }
    
    /**
     * A method for showing wether a loan is home or not.
     */
    public boolean getStatus()
    {
        return home;
    }
    
    /**
     * A method for find a persons name
     * @return String persons name.
     */
    public String getPerson()
    {
        return loanperson.getName();
    }
    
    /**
     * A method that returns the title of 1 or more dvds currently registered
     * to this loan, collects the titles and puts them into an ArrayList.
     * @return ArrayList dvds
     */
    public ArrayList<String> getDVD()
    {
        ArrayList<String> dvds = new ArrayList<String>();
        for(DVD d : showdvds)
        {
            dvds.add(d.getTitle());
        }
        return dvds;
    }
    
    /**
     * A method that returns the serial nr of all the copies registered to this loan
     * collects serialnrs and then converts them to string format, before adding them
     * to the new ArrayList.
     * @return ArrayList copies.
     */
    public ArrayList getCopy()
    {
        ArrayList<String> copies = new ArrayList<String>();
        for(Copy c: loandvds)
        {
            copies.add(Long.toString(c.getSerialnr()));
        }
        return copies;
    }

    /**
     * A mutator method for setting a new deliveryDateDay, 
     * @param inting deliveryDateDay
     */
    public void setDeliveryDateDay(int deliveryDateDay)
            
    {
        
        this.deliveryDateDay = deliveryDateDay;
    }
    
    /**
     * An accessor method that returns the value of deliveryDateDay
     * @return int deliveryDateDay
     */
    public int getDeliveryDateDay()
    {
        return deliveryDateDay;
    }
    
    
        
}